package com.sunfeng.chap4.test2;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * @description:
 * @author: 孙 峰
 * @time: 2020/11/9 14:39
 */
public class CreateWebServer {
    public static void main(String[] args) {
        try {
            ServerSocket serverSocket = new ServerSocket(6666);
            Socket socket = serverSocket.accept();
            // 从socket中获取inputStream信息
            InputStream inputStream = socket.getInputStream();

            InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
            BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
            String getString="";
            while (!"".equals(getString= bufferedReader.readLine())){
                System.out.println(getString);
            }
            OutputStream outputStream = socket.getOutputStream();
            outputStream.write("1111111111111111111111".getBytes());
            outputStream.flush();
            inputStream.close();
            outputStream.close();
            socket.close();
            serverSocket.close();

        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
